<template>
    <div>
        <el-descriptions title="新增跟进" direction="vertical" :column="2" border style="margin-top: 20px">
            <el-descriptions-item label="内容" :span="2">
                <el-input v-model="data.content" :rows="2" type="textarea" autosize placeholder="请输入内容" />
            </el-descriptions-item>
            <el-descriptions-item label="跟进方式">
                <el-select v-model="data.followWay" clearable placeholder="请选择跟进方式">
                    <el-option v-for="item in date.followWay" :key="item.id" :label="item.value" 
                    :value="item.id" />
                </el-select>
            </el-descriptions-item>
            <el-descriptions-item label="下次联系时间">
                <el-date-picker v-model="data.nextConnectionTime" value-format="YYYY-MM-DD" type="datetime"
                    placeholder="选择日期" />
            </el-descriptions-item>
            <el-descriptions-item label="操作" :span="2">
                <el-button type="primary" @click="methods.add">新增</el-button>
            </el-descriptions-item>
        </el-descriptions>
    </div>
</template>

<script setup lang="ts">
import { ref, onMounted,defineProps,reactive,defineEmits } from "vue";
import { ElMessage } from 'element-plus';
import { addFollowOfflineCustomers } from '@/api/FollowOfflineCustomers/index';
import { getFollowWay } from '@/api/Dictionarys/index';

const props = defineProps({
    data: {
        type: Object,
        default: () => ({}),
        required: true,
    },
});
const data = reactive({
    content: "",
    followWay: "",
    customerId: "",
    nextConnectionTime: ""
});
//跟进方式
interface FollowWay {
    id: string;
    value: string;
    dictionaryTypeId: string;
    createTime: string;
}
interface Date {
    followWay: FollowWay[];
}
const date = reactive<Date>({
    followWay: [],
});
const emit = defineEmits(['myclose']);
const methods={
    async bind(){
        const res = await getFollowWay();
        if (res.code === 0) {
            date.followWay = res.data.data;
        }
    },
    async add(){
        if (data.content.trim() === "") {
            ElMessage.error('跟进内容不允许为空')
            return;
        }
        if (data.followWay.trim() === "") {
            ElMessage.error('跟进方式不允许为空')
            return;
        }
        if (data.nextConnectionTime.trim() === "") {
            ElMessage.error('下次联系时间不允许为空')
            return;
        }
        const res = await addFollowOfflineCustomers({
            ...data
        });
        if (res.code === 0) {
            ElMessage.success(res.message);
            emit('myclose');
        } else {
            ElMessage.error(res.message);
        }
    }
}
onMounted(() => {
    // data.id = route.params.id;
    methods.bind();
    data.customerId=props.data.id;
    // console.log(route.params.id)
});
</script>

<style scoped></style>